#include"macro.h"

namespace daniel
{
    void bt()
    {
        void* buffer[BT_BUF_SIZE];
        auto nptrs=backtrace(buffer,BT_BUF_SIZE);
        char** strings;
        strings=backtrace_symbols(buffer,nptrs);
        if (strings==nullptr){
            std::cout<<"backtrace error!"<<std::endl;
        }
        std::cout<<std::string(30,'*')<<"BackTrace as follows:"<<std::string(30,'*')<<std::endl;
        for(int i=0;i<nptrs;i++){
            std::cout<<"["+std::to_string(i)+"]"+":"<<strings[i]<<std::endl;
        }
        std::cout<<std::string(30,'*')<<"  BackTrace as end!  "<<std::string(30,'*')<<std::endl;
        free(strings);
    }

    // //断言功能
    // void assert2(bool expression, const std::string& info)
    // {
    //     if (expression==false){
    //         std::cout<<info<<std::endl;
    //         bt();
    //     }
    //     assert(expression);
    // }
}